<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input id="p" />
		  <select id="sel" >
		  	<option value="add">+</option>
		  	<option value="sub">-</option>
		  	<option value="cheng">*</option>
		  	<option value="chu">/</option>
		  </select>
		<input id="w" />
		<input type="button" value="计算" onclick="jisuan();" />
		<input id="jg" />
	</body>
	<script>
	
		function jisuan(){
			 // var obj=document.getElementById("sel");
			 // var index=obj.selectedIndex;
			  //var opval=obj.options[index].value;
				//var sum=0;
		    var opval=document.getElementById("sel").value;
			var p=parseInt(document.getElementById("p").value);
		
		    var w=parseInt(document.getElementById("w").value);
		    var result=parseInt(document.getElementById("jg").value);
		if(opval=='add'){
		
		
		    result=p+w;
		 document.getElementById("jg").value=result;
			//错误的写法
			// var jg=document.getElementById("jg").value;
			 //jg=parseInt(p)+parseInt(w);
		
		 }else if(opval=='sub'){
		
		
		  result=p-w;
		  document.getElementById("jg").value=result;
			//错误的写法
			// var jg=document.getElementById("jg").value;
			 //jg=parseInt(p)+parseInt(w);
		}else if(opval=='cheng'){
			  result=p*w;
			document.getElementById("jg").value=result;
		}else if(opval=='chu'){
			  result=p/w;
			document.getElementById("jg").value=result;
		}
			
		}
		
	</script>
</html>
